/**
 * Adapter for displaying the list of specimens in a bag
 */

package edu.washington.cs.labspecimentransport.adapters;

import java.util.Map;
import java.util.Set;

import edu.washington.cs.labspecimentransport.R;
import edu.washington.cs.labspecimentransport.dataobjects.ItemAttribute;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ColorAdapter extends BaseAdapter {

	private Context context;
	private Map<ItemAttribute,Integer> colorMap;
	private ItemAttribute[] colors;
	
	public ColorAdapter(Context context, Map<ItemAttribute, Integer> map) {
		this.context = context;
		this.colorMap = map;
		Set<ItemAttribute> tempSet = colorMap.keySet();
		this.colors = new ItemAttribute[tempSet.size()];
		tempSet.toArray(this.colors);
	}

	public int getCount() {
		return colors.length;
	}

	public ItemAttribute getItem(int pos) {
		return colors[pos];
	}

	public long getItemId(int pos) {
		return pos;
	}

	public View getView(int position, View view, ViewGroup parent) {
		ItemAttribute selected = this.getItem(position);
		LinearLayout itemLayout = (LinearLayout) 
			LayoutInflater.from(context).inflate(R.layout.dialog_single, parent, false);
		
		String color = selected.getDisplay_text();
		int colorCount = colorMap.get(selected);
		
		// display the color of vial and its count
		TextView itemIdField = (TextView) itemLayout.findViewById(R.id.dialog_single_text);
		itemIdField.setText(color + ": " + colorCount);
		
		return itemLayout;
	}
}
